<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var obj={
            name:"我儿子",
            age:21,
            address:"中国",

            // 迭代器
            [Symbol.iterator](){
                var n=-1;
                var list=Object.keys(this);
                console.log(list);
                return{
                    next(){
                        n++;
                        return{
                            value:list[n],
                            done:list.length==n
                        }
                    }
                }
            }
        }
        for(var k of obj){
            console.log(k);
        }
        // for...of不能直接遍历对象,需要在对象里添加Symbol.iterator
        // 或者使用Object.keys(),Object.values(),Object.entries()
    </script>
</body>
</html>